package com.link2room.rodimus.controller.api;

import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.rodimus.dto.param.api.MemberLevelBaseFindParamDto;
import com.link2room.rodimus.dto.param.base.MemberLevelBaseDto;
import com.link2room.rodimus.facade.IMemberLevelFacadeService;
import io.swagger.annotations.Api;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by LN on 2017/11/16
 */
@Api(tags = "会员等级相关")
@RestController
@RequestMapping("/api/MemberLevels")
public class MemberLevelApiController {

    @Resource
    private IMemberLevelFacadeService memberLevelFacadeService;


    @RequestMapping(method = RequestMethod.GET)
    public BaseResultDto memberLevels(
            @RequestParam(name = "needDetail",required = false)String needDetail
    ) throws Exception {
        MemberLevelBaseFindParamDto paramDto = new MemberLevelBaseFindParamDto();
        paramDto.setNeedDetail(needDetail);
        BaseResultDto res = new BaseResultDto();
        res.setResultCode(0);
        res.setQueryResult(memberLevelFacadeService.selectMemberLevelBaseDto(paramDto));
        return res;
    }
    @RequestMapping(value="/{memberLevel}",method = RequestMethod.GET)
    public BaseResultDto memberLevels(
            @RequestParam(name = "needDetail", required = false) String needDetail,
            @PathVariable("memberLevel") String memberLevels) throws Exception {
        MemberLevelBaseFindParamDto paramDto = new MemberLevelBaseFindParamDto();
        paramDto.setMemberLevel(memberLevels);
        paramDto.setNeedDetail(needDetail);
        BaseResultDto res = new BaseResultDto();
        res.setResultCode(0);
        List<MemberLevelBaseDto> dtoList = memberLevelFacadeService.selectMemberLevelBaseDto(paramDto).getResultlist();
        res.setResultInfo(CollectionUtils.isEmpty(dtoList)?null:dtoList.get(0));
        return res;
    }
}
